<?php
namespace app\user\controller;

use think\Controller;
use think\facade\Request;
use app\app\model\App as AppModel;

class Base extends Controller {
    protected function getCurrentSiteName(){
        $currentSite = Request::get('site', 'unknow');
        $site = AppModel::getByName($currentSite);
        if(!$site){
            $currentSite = 'unknow';
        }
        return $currentSite;
    }

	protected function getCurrentSiteTitle(){
        $currentSite = $this->getCurrentSiteName();
        $site = AppModel::getByName($currentSite);
        if($site){
            return $site->title;
        } else {
            return config('app.app_name');
        }
    }

    protected function getOtherSiteTitle(){
        $sites = config('app.sites');
        $titles = [];
        $currentSite = $this->getCurrentSiteName();
        $sites = AppModel::getSiteExcept($currentSite);
        if(count($sites) == 0){
            return false;
        } else {
            foreach($sites as $site){
                $titles[] = $site->title;
            }
            return implode('、', $titles);
        }
    }
}